package com.fight.strive.sys.modules.rbac.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fight.strive.sys.modules.common.PageR;
import com.fight.strive.sys.modules.common.ReStatus;
import com.fight.strive.sys.modules.rbac.dto.RbacDepartmentTreeDto;
import com.fight.strive.sys.modules.rbac.entity.RbacDepartmentEntity;
import com.fight.strive.sys.modules.rbac.service.RbacDepartmentService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/sys/rbac/department")
public class RbacDepartmentController {

    @Resource
    private RbacDepartmentService rbacDepartmentService;

    @PostMapping("/save")
    public ReStatus<Void> saveDepartment(@RequestBody RbacDepartmentEntity entity) {
        rbacDepartmentService.saveDepartment(entity);
        return ReStatus.success();
    }

    @PostMapping("/listDepartmentTree")
    public ReStatus<List<RbacDepartmentTreeDto>> listDepartmentTree() {
        return ReStatus.success(
                rbacDepartmentService.getDepartmentTree(0L));
    }

    @PostMapping("/listByPage")
    public ReStatus<IPage<RbacDepartmentEntity>> listByPage(
            @RequestBody PageR<RbacDepartmentEntity> page) {
        return ReStatus.success(
                rbacDepartmentService.listByPage(page));
    }
}
